home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 8724 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.8 KB

  1. Path: news.microsoft.com!news
  2. From: a-cnadc@microsoft.com (Dann Corbit)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: f;oating point precision
  5. Date: 6 Mar 1996 02:28:28 GMT
  6. Organization: Microsoft Corporation
  7. Message-ID: <4hit8c$8lm@news.microsoft.com>
  8. References: <c0d_9603050128@csource.blaze.net.au>
  9. NNTP-Posting-Host: 157.57.171.202
  10. Mime-Version: 1.0
  11. X-Newsreader: WinVN 0.93.14
  12.  
  13. In article <c0d_9603050128@csource.blaze.net.au>, David.Burrows@f158.n633.z3.fidonet.org says...
  14. >
  15. >Help.... I am getting floating point innaccuracies at about the 4th decimal
  16. >
  17. >place. eg i enter 510.0250 and it comes out as 510.0249.
  18. >I am just starting to learn c so please excuse my ignorance.
  19. >                                                             dave
  20. >
  21. >--
  22. >David.Burrows@f158.n633.z3.fidonet.org, David Burrows 3:633/158 (FidoNet)
  23. >
  24. Most people like to use base ten numbers in calculations.  Computers store
  25. numbers in binary (base two).  Performing this conversion from base ten to 
  26. base two causes the problem that you see.  In addition, a four byte IEEE 
  27. float will hold six to seven decimal digits of accuracy.  An eight byte 
  28. double will hold about 15 digits of accuracy.  Fixed word length limits the
  29. ability of computers to get exact results.  We have similar limitations as
  30. humans when we express things in floating point.  For instance, take the
  31. numbers 1/9 and 1/7 and express them as decimal numbers to as many places 
  32. as you like.  Then multiply the decimal expansions together.  Multiply the
  33. result by 63.  If you do it on paper, you won't get "1" unless you have used
  34. an infinite expansion.
  35. -- 
  36. The opinions expressed in this message are my own personal views
  37. and do not reflect the official views of Microsoft Corporation.
  38. In fact, I'm just a subcontractor, not an employee, so pull in your claws.
  39.  
  40.